/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.CompanyInfo;
/*    */ import com.newcrm.bean.Group;
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.UserManager;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.util.List;
/*    */ import javax.servlet.RequestDispatcher;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class ListUsers extends AbstractAction
/*    */ {
/* 24 */   private static Logger logger = Logger.getLogger(ListUsers.class.getName());
/*    */ 
/*    */   public ListUsers(AbstractHttpServlet servlet) {
/* 27 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 34 */     User loginUser = super.getLoginUser(request);
/*    */ 
/* 36 */     if ((!loginUser.isAdmin) && (!loginUser.isGroupAdmin)) {
/* 37 */       request.getRequestDispatcher("/nopermission.jsp").forward(
/* 38 */         request, response);
/* 39 */       logger.warn("is not admin");
/* 40 */       return;
/*    */     }
/*    */ 
/* 43 */     int groupId = Util.getURLIntParameter(request.getParameter("groupId"));
/*    */ 
/* 45 */     if ((!loginUser.isAdmin) && (groupId <= 0)) {
/* 46 */       groupId = loginUser.groupId;
/*    */     }
/*    */ 
/* 49 */     String groupIds = "";
/*    */ 
/* 51 */     if (groupId == 0) {
/* 52 */       groupIds = "";
/*    */     } else {
/* 54 */       CompanyInfo company = super.getCompany(loginUser.companyId);
/* 55 */       if (!loginUser.isAdmin)
/*    */       {
/* 57 */         if (!company.isGroupAdmin(loginUser, groupId)) {
/* 58 */           request.getRequestDispatcher("/nopermission.jsp")
/* 59 */             .forward(request, response);
/* 60 */           logger.warn("is not Group admin");
/* 61 */           return;
/*    */         }
/*    */       }
/*    */ 
/* 65 */       Group group = company.getGroupById(groupId);
/* 66 */       if (group == null) {
/* 67 */         request.getRequestDispatcher("/nopermission.jsp").forward(
/* 68 */           request, response);
/* 69 */         logger.warn("is not Group admin");
/* 70 */         return;
/*    */       }
/* 72 */       groupIds = group.getAllIds();
/*    */     }
/*    */ 
/* 75 */     UserManager manager = new UserManager();
/* 76 */     List users = manager.getCompanyUsers(loginUser.companyId, 
/* 77 */       groupIds);
/*    */ 
/* 79 */     request.setAttribute("users", users);
/* 80 */     request.setAttribute("groupId", Integer.valueOf(groupId));
/* 81 */     request.getRequestDispatcher("/userManager.jsp").forward(request, 
/* 82 */       response);
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ListUsers
 * JD-Core Version:    0.6.1
 */